package com.tianzeculture.stagebao.activity.artist;

import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.mabeijianxi.smallvideorecord2.DeviceUtils;
import com.mabeijianxi.smallvideorecord2.JianXiCamera;
import com.mabeijianxi.smallvideorecord2.MediaRecorderActivity;
import com.mabeijianxi.smallvideorecord2.model.MediaRecorderConfig;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.video.SendSmallVideoActivity;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.dialog.PublicationDialog;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.util.ImageUtils;

import java.io.File;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.valuesfeng.picker.Picker;
import io.valuesfeng.picker.engine.GlideEngine;
import io.valuesfeng.picker.utils.PicturePickerUtils;


public class PublishWorksActivity extends BaseActivity implements PublicationDialog.OnSelectClickListener {
    @BindView(R.id.tvShortVideo)
    TextView tvShortVideo;
    @BindView(R.id.tvPicture)
    TextView tvPicture;
    PublicationDialog dialog;
    private List<Uri> mSelected;
    private List<String> uris;
    private static final int REQUEST_CODE_CHOOSE = 66;

    @Override
    public void initUI() {
        super.initUI();
    }

    @OnClick({R.id.tvShortVideo, R.id.tvPicture})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.tvShortVideo:
                dialog = new PublicationDialog(this, 1);
                dialog.setOnSelectClickListener(this);
                dialog.show();
                break;
            case R.id.tvPicture:
                startActivity(new Intent(this, SendSmallVideoActivity.class).putExtra("isVideo", false));
//                Picker.from(this)
//                        .count(9)
//                        .enableCamera(true)
//                        .setEngine(new GlideEngine())
//                        .forResult(REQUEST_CODE_CHOOSE);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_CODE_CHOOSE:
                if (resultCode == RESULT_OK && data != null) {
                    Uri uri = data.getData();
                    String vedioUri = ImageUtils.getRealPathByURI(uri, this);
                    Intent intent = new Intent(this, SendSmallVideoActivity.class);
                    intent.putExtra("video_uri", vedioUri);
                    startActivity(intent);
                }
                break;
        }
    }


    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_publish_works;
    }

    @Override
    public void onOk(boolean isTakePic, int type) {
        if (type == 1) {
            if (isTakePic) {
                MediaRecorderConfig config = new MediaRecorderConfig.Buidler()
                        .fullScreen(true)
                        .recordTimeMax(15000)
                        .recordTimeMin(1500)
                        .maxFrameRate(20)
                        .videoBitrate(600000)
                        .captureThumbnailsTime(1)
                        .build();
                MediaRecorderActivity.goSmallVideoRecorder(this, SendSmallVideoActivity.class.getName(), config);
            } else {
                Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, REQUEST_CODE_CHOOSE);
            }
        }
    }

    @Override
    public void onCancel() {

    }
}
